<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/smoothness/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />							<!-- 本專案自行定義 CSS -->
<script src="js/jquery-1.9.1.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>									<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																		<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>													<!-- 本專案自行定義 JS -->

<style>
  .ui-menu {
    width: 200px;
  }
  </style>

<title>DPS部署交付系統</title>

<script type="text/javascript">

$(document).ready(function() {
	if ($.cookie("userId") == null) {
		alert("請先登入系統");
		location.assign("index.html");
	} else {
		$.post("QuerySystemList",function(reses) {
			$("h3#banner").html( reses.name );
			$.cookie("systemName",reses.name);
		},"JSON");
		initPage();
		
		if ( $.cookie("accessList") == "NoRight" )  {
			$.post("UserAuthority",{userId:$.cookie("userId"),isSU:$.cookie("isSU")},function(reses) {
				var preRoleId = 999;
				var accessList = "";
				if ( reses.length != 0 ) {
					$.each( reses,function(i, res) {

						var roleId = res.intA;
						
						if (preRoleId != roleId) {
						 	if (preRoleId != 999){
								accessList += splitTokenONE + res.intA+":"+res.strA;		//用splitTokenONE來區分不同的 role
							} else {
								accessList = res.intA+":"+res.strA;
							}
							/** 主要的功能別 **/
							$("#menu").append("<li><a href='#'>"+res.strA+"</a><ul id='ulRole"+roleId+"'></ul></li>");
						}

						accessList += splitTokenTWO + res.intB+":"+res.strB+":"+res.strC;		//用splitTokenTWO來區分不同的 function
						
						/** 功能細項 **/
						$("#ulRole"+roleId).append("<li><a href='"+ res.strC +"'>"+res.strB+"</a></li>");
						preRoleId = roleId;	
					});
					
					$.cookie("accessList",accessList);	
				}
				$("#menu").menu();
			});
		} else {
			var accessList = $.cookie("accessList").split( splitTokenONE );
			for ( i=0; i < accessList.length ; i++ ) {
				var tmp = accessList[i].split( splitTokenTWO );
				$("#menu").append("<li><a href=\"#\">"+tmp[0].split(":")[1]+"</a><ul id=\"ulRole"+tmp[0].split(":")[0]+"\"></ul></li>");
				
				for ( j=1; j < tmp.length ; j++ ) {
					$("#ulRole"+ tmp[0].split(":")[0] ).append("<li id='f"+tmp[j].split(":")[0]+"'><a href='"+ tmp[j].split(":")[2] +"'>"+tmp[j].split(":")[1]+"</a></li>");
				}
			}
			$("#menu").menu();
		}
	}
}).tooltip();
</script>
</head>
<body>
	<div>
		<table>
			<tr>
				<td class="mm"><img id='imgLoading' src='pic/home.jpg'></td>
				<td class="mm"><h3 id='banner'></h3>--部署交付系統--</td>
				<td><img id='logout' src='pic/logout.png'></td>
			</tr>
			<tr class='right'>
				<td id="user" colspan="3"></td>
			</tr>
		</table>
	</div>
	<p><p>
	<ul id="menu"></ul>
</body>
</html>